package com.jerry.huihome.module.find_near_mine.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jerry.huihome.R;
import com.jerry.huihome.base.BaseApplication;
import com.jerry.huihome.base.BaseViewHolder;
import com.jerry.huihome.base.MyBaseAdapter;
import com.jerry.huihome.module.find_near_mine.activity.AfflatuspictoActivity;
import com.jerry.huihome.module.find_near_mine.entity.AfflatusListEntity;
import com.jerry.huihome.views.RoundImageView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;

import java.util.List;

import butterknife.BindView;

/**
 * Created by axiang on 2016/5/10.
 */
public class AfflatusListAdapter extends MyBaseAdapter<AfflatusListEntity.BodyBean.WorksBean>{
    private final Context context;
    private final List<AfflatusListEntity.BodyBean.WorksBean> list;
    private final ImageLoader imageLoader;
    private final LayoutInflater layoutInflater;
    private AfflatusViewHolder afflatusViewHolder;
    private final DisplayImageOptions options;
    private DisplayImageOptions options1;

    public AfflatusListAdapter(Context context, List<AfflatusListEntity.BodyBean.WorksBean> list){
        super(context, list);
        this.context = context;
        this.list = list;
        layoutInflater = LayoutInflater.from(context);
        imageLoader = BaseApplication.getApplication().getImageLoader();
        options = BaseApplication.getApplication().getImageOptions();
    }

    public List<AfflatusListEntity.BodyBean.WorksBean> getList(){
        return list;
    }

    @Override
    public int getLayoutId(){
        return R.layout.afflatus_pull_list;
    }

    @Override
    public BaseViewHolder getViewHolder(){
        return new AfflatusViewHolder();
    }

    @Override
    public void bindViews(View view, BaseViewHolder viewHolder){
        options1 = new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisk(true)
                .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2).bitmapConfig(Bitmap.Config.ARGB_8888).build();
        AfflatusViewHolder afflatusViewHolder = (AfflatusViewHolder) viewHolder;
        final AfflatusListEntity.BodyBean.WorksBean worksBean = getItem(viewHolder.position);
        //AfflatusListEntity.BodyBean.WorksBean worksBean = afflatusListEntity.getWorks().get(viewHolder.position);
        String url1 = worksBean.getDesignerAvatar();
        String url2 = worksBean.getCoverimg();
        imageLoader.displayImage(url1,afflatusViewHolder.ivtouxiang,options1);
        imageLoader.displayImage(url2,afflatusViewHolder.ivimages,options1);
        afflatusViewHolder.tvname.setText(worksBean.getDesignerName());
        afflatusViewHolder.tvprofession.setText(worksBean.getDesignerTitle());
        afflatusViewHolder.tvdescription.setText(worksBean.getWorkname());
        afflatusViewHolder.tvattentioncount.setText(worksBean.getAppraiseCount()+"");
        afflatusViewHolder.tvpraisecount.setText(worksBean.getCommentCount()+"");
        afflatusViewHolder.tvsharecount.setText(worksBean.getShareCount()+"");
        afflatusViewHolder.ivimages.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                Intent intent = new Intent();
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                intent.putExtra("id", worksBean.getId());
                intent.setClass(context, AfflatuspictoActivity.class);
                context.startActivity(intent);
            }
        });
    }

    public class AfflatusViewHolder extends BaseViewHolder{
        @BindView(R.id.touxiang)
        RoundImageView ivtouxiang;
        @BindView(R.id.name)
         TextView tvname;
        @BindView(R.id.profession)
         TextView tvprofession;
        @BindView(R.id.images)
         ImageView ivimages;
        @BindView(R.id.description)
         TextView tvdescription;
        @BindView(R.id.attentioncount)
         TextView tvattentioncount;
        @BindView(R.id.praisecount)
        TextView tvpraisecount;
        @BindView(R.id.sharecount)
         TextView tvsharecount;



       /* public AfflatusViewHolder(View view){
            ivtouxiang =
        }*/
    }
}
